
#include <BPainter>
#include <BRender>
#include <BViewer>
#include <BCone>
#include <BCube>
#include <BReadWrite>
#include <BImage>
#include <BScene>

#include "PointHandler.h"

PointHandler::PointHandler()
{
	_nodeA = new BBody("nodeA");
	{
		_nodeA->setMass(3.0);

		BCube* cube = new BCube(5, 12);
		cube->setColor(100, 200, 255);
		_nodeA->insertShape(cube);
	}

	_nodeB = new BBody("nodeB");
	{
		_nodeB->setMass(1.0);

		BImage* image = ReadFile<BImage>("data/picture/whitemetal_diffuse.jpg");

		BCone* cone = new BCone(0.5, 2, 24, 10);
		cone->setColor(200, 100, 0);
		cone->setTexture(image);
		_nodeB->insertShape(cone);
	}

	BVector pointA = _nodeA->space().max();
	BVector pointB(0, 0, _nodeB->space().max().z());
	_pointRestraint = new BPointRestraint(_nodeA, pointA, _nodeB, pointB);
	_pointRestraint->setName("Point");
}
PointHandler::~PointHandler()
{

}

void PointHandler::attached(BViewer* viewer)
{
	BScene* dscene = (BScene*)viewer->scene();
	_nodeA->setPosition(0, 0, 13);
	_nodeB->setPosition(2, 2, 13);
	dscene->insert(_nodeA);
	dscene->insert(_nodeB);
	dscene->insert(_pointRestraint);
	this->emit("edit-restraint", _pointRestraint);
}
void PointHandler::detached(BViewer* viewer)
{
	BScene* dscene = (BScene*)viewer->scene();
	dscene->remove(_nodeA);
	dscene->remove(_nodeB);
	dscene->remove(_pointRestraint);
}

void PointHandler::paint(BPainter& painter)
{
	BViewer* viewer = this->viewer();
}
void PointHandler::render(BRender& render)
{
	render.setLighting(false);
	render.setDepthTest(false);
	render.setLineSmooth(true);
	render.setLineWidth(1);
	
}
